part of '../repository.dart';

const _kPurchasedItemAcknowledgedAcknowledgementStatusValue = 'acknowledged';
const _kPurchasedItemYetToBeAcknowledgedAcknowledgementStatusValue = 'yet_to_be_acknowledged';
const _kPurchasedItemUnacknowledgeableAcknowledgementStatusValue = 'unacknowledgeable';

class _PurchasedItemAcknowledgementStatusDto extends Equatable {
  const _PurchasedItemAcknowledgementStatusDto._internal({
    required this.acknowledgementStatusString,
  });

  final String acknowledgementStatusString;

  @override
  List<Object?> get props {
    return [
      acknowledgementStatusString,
    ];
  }

  factory _PurchasedItemAcknowledgementStatusDto.fromString(String acknowledgementStatusString) {
    return _PurchasedItemAcknowledgementStatusDto._internal(
      acknowledgementStatusString: acknowledgementStatusString,
    );
  }

  factory _PurchasedItemAcknowledgementStatusDto.fromEntity(
      GooglePlayPurchasedItemAcknowledgementStatus acknowledgementStatus) {
    late final String acknowledgementStatusString;

    if (acknowledgementStatus == GooglePlayPurchasedItemAcknowledgementStatus.acknowledged) {
      acknowledgementStatusString = _kPurchasedItemAcknowledgedAcknowledgementStatusValue;
    } else if (acknowledgementStatus ==
        GooglePlayPurchasedItemAcknowledgementStatus.yetToBeAcknowledged) {
      acknowledgementStatusString = _kPurchasedItemYetToBeAcknowledgedAcknowledgementStatusValue;
    } else if (acknowledgementStatus ==
        GooglePlayPurchasedItemAcknowledgementStatus.unacknowledgeable) {
      acknowledgementStatusString = _kPurchasedItemUnacknowledgeableAcknowledgementStatusValue;
    }

    return _PurchasedItemAcknowledgementStatusDto._internal(
      acknowledgementStatusString: acknowledgementStatusString,
    );
  }

  @override
  String toString() {
    return acknowledgementStatusString;
  }

  GooglePlayPurchasedItemAcknowledgementStatus toEntity() {
    if (acknowledgementStatusString == _kPurchasedItemAcknowledgedAcknowledgementStatusValue) {
      return GooglePlayPurchasedItemAcknowledgementStatus.acknowledged;
    }

    if (acknowledgementStatusString ==
        _kPurchasedItemYetToBeAcknowledgedAcknowledgementStatusValue) {
      return GooglePlayPurchasedItemAcknowledgementStatus.yetToBeAcknowledged;
    }

    if (acknowledgementStatusString == _kPurchasedItemUnacknowledgeableAcknowledgementStatusValue) {
      return GooglePlayPurchasedItemAcknowledgementStatus.unacknowledgeable;
    }

    throw UnimplementedError();
  }
}
